Skip to content

Fix chart date alignment: use date intersection instead of index-based pairing#58

Merged
lukepring merged 3 commits intoSprint-2-Jackfrom
copilot/sub-pr-55-another-one
Mar 20, 2026
Merged

Fix chart date alignment: use date intersection instead of index-based pairing#58
lukepring merged 3 commits intoSprint-2-Jackfrom
copilot/sub-pr-55-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Chart series were paired by array index (n = min(data1.size(), data2.size())), silently comparing prices from different calendar dates whenever trading days diverge between symbols.

Changes

  • Date-aligned series: Build Map<LocalDate, PriceData> for each symbol and compute the intersection of dates before plotting — every x-coordinate now maps to the same calendar date for both symbols
  • Duplicate date handling: toMap uses a merge function (existing, replacement) -> existing to avoid IllegalStateException on duplicate dates in a series
  • Empty intersection guard: Returns an error to the user if no overlapping trading dates exist in the selected range
// Before — index-based, silently misaligns on missing days
int n = Math.min(data1.size(), data2.size());
for (int i = 0; i < n; i++) {
    PriceData p1 = data1.get(i);  // may be a different date than p2
    PriceData p2 = data2.get(i);
    ...
}

// After — date-intersection aligned
Map<LocalDate, PriceData> map1 = data1.stream()
        .collect(Collectors.toMap(PriceData::getDate, p -> p, (e, r) -> e));
Map<LocalDate, PriceData> map2 = data2.stream()
        .collect(Collectors.toMap(PriceData::getDate, p -> p, (e, r) -> e));

Set<LocalDate> commonDates = new LinkedHashSet<>(map1.keySet());
commonDates.retainAll(map2.keySet());
List<LocalDate> sortedDates = new ArrayList<>(commonDates);
sortedDates.sort(Comparator.naturalOrder());

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: lukepring <68820847+lukepring@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback from review on Sprint 2 jack PR Fix chart date alignment: use date intersection instead of index-based pairing Mar 20, 2026
Copilot AI requested a review from lukepring March 20, 2026 15:51
@lukepring lukepring marked this pull request as ready for review March 20, 2026 15:56
@lukepring lukepring merged commit bbd8485 into Sprint-2-Jack Mar 20, 2026
@lukepring lukepring deleted the copilot/sub-pr-55-another-one branch March 20, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants